class Solution {
public:

    //static cmp(int i, int j) {

    vector<int> twoSum(vector<int> &numbers, int target) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
      vector<pair<int, int> > pairs;
      int n = numbers.size();

      for (int i = 0; i < n; ++i) {
        pairs.push_back(make_pair(numbers[i], i));
      }
      sort(pairs.begin(), pairs.end());

      int index1 = 0;
      int index2 = 0;

      for (int i = 0, j = n - 1; i < n; ++i) {
          while (i < j && pairs[i].first + pairs[j].first > target) {
            --j;
          }
          if (i >= j) {
            break;
          }
          if (pairs[i].first + pairs[j].first == target) {
            index1 = pairs[i].second + 1;
            index2 = pairs[j].second + 1;
          }
        }
      if (index1 > index2) {
        swap(index1, index2);
      }
      vector<int> result;
      result.push_back(index1);
      result.push_back(index2);
      return result;

    }
};
